<template>
    <view style="padding: 10px 20px;">
        <u-search placeholder="日照香炉生紫烟" v-model="keyword"></u-search>
        <view style="margin-top: 40upx;">
            <view v-for="(item,index) in projectList" :key="index" style="margin-bottom: 20upx;" @click="handleClick(item)">
                <view class="between-center">
                     <view class="flex">
                        <h3 style="margin-right: 20upx;">{{item.fullname}}</h3>
                        <!-- <u-tag text="标签" plain size="mini" type="warning"></u-tag> -->
                    </view>
                    <u-icon name="star" :color="item.is_collect ? 'orange' : '#666'" @click.stop="handleMainCollect(item,e)"></u-icon>
                </view>
                
                <view class="project_desc">{{item.smalltext}}</view>
                <view class="project_desc" style="color: #666;">{{item.fulltext}}</view>
                <img :src="item.xiangmu_fengmian_img" alt="" class="project_img">
            </view>
        </view>
    </view> 
  </template>
  
  <script>
  export default {
    data() {
      return {
        keyword: 'Hello',
        value1: 0,
        value2: 'a',
        option1: [
          { text: '全部商品', value: 0 },
          { text: '新款商品', value: 1 },
          { text: '活动商品', value: 2 }
        ],
        option2: [
          { text: '默认排序', value: 'a' },
      ],
      projectList:[]
      }
    },
    onShow() {
        this.getInit()
        this.getList()
    },
    methods: {
        handleClick(item){
            uni.navigateTo({
                url:'/pages/project/details',
                success:  (res) => {
                    // 向目标页面发送数据
                    res.eventChannel.emit('acceptDataFromSourcePage', { param:item });
                }
            })
        },
        async getInit (){
            await this.$api.getProjectType({})
        },
        async getList (){
            const res = await this.$api.getProject({
                uid:uni.getStorageSync('userInfo').uid || 0
            })
            console.log('111');
            console.log(res);
            this.projectList = res
        },
        async handleMainCollect(item,e){
            console.log(item,e);
                const res = await this.$api.addCollect({
                    id:item.id,
                    category:'product_xiangmu'
                })
                global.showToast('收藏成功')
                return false
            }
            
    },
  }
  </script>
  <style scoped>
  .project_desc{
    font-size: 24upx;
    color: #999;
    font-weight: 400;
    margin-top: 10upx;
  }
  .project_img{
    width: 100%;
    background: #f0f0f0;
    border-radius: 20upx;
    margin-top: 20upx;
  }
</style>
  